function [out,out2]=modulation(in, M, N)
    length = size(in, 2);
    symbols = length / N;
    out = zeros(1, length + symbols * M);
    for i=0:symbols-1
        for m=0:N-1
            sum = 0;
            for k=0:N-1
                sum = sum + in(i * N + k+1)*exp(1j*2*pi*k*m/N);
            end
            out(i * (M+N) + M + m+1) = sum / sqrt(N);
        end
        out(i * (M+N) + 1:i * (M+N) + M) = out(i * (M+N) + N+1:i * (M+N) + N + M);
    end
    
    out2 = zeros(1, N);
    for m=0:N-1
        sum = 0;
        for k=0:N-1
            sum = sum + in(k+1)*exp(1j*2*pi*k*m/N);
        end
        out2(m+1) = sum / sqrt(N);
    end
    out2 = [(out2(N-M+1:N)) out2];
end